package com.defysoft.waukids.slide;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.defysoft.waukids.BaseActivity;
import com.defysoft.waukids.R;
import com.defysoft.waukids.main.Main_JoinYacguan;

public class Main_Slide_Info extends BaseActivity implements OnClickListener{
	Toolbar toolbar;
	TextView textView[] = new TextView[8];
	int license_clock = 0;
	
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.main_slide_info_activity);
		setStartData();
		setToolbar();

		registerReceiver(mToastMessageReceiver, new IntentFilter(
				"com.defysoft.waukids.TOAST_MESSAGE"));
	}
	@Override
	public void setStartData() {
		super.setStartData();
		textView[0] =(TextView)findViewById(R.id.MAIN_SLIDE_INFO_TEXTVIEW_EXPLANATION);
		textView[1] =(TextView)findViewById(R.id.MAIN_SLIDE_INFO_TEXTVIEW_CONTACT);
		textView[2] =(TextView)findViewById(R.id.MAIN_SLIDE_INFO_TEXTVIEW_COPYRIGHT);
		textView[3] =(TextView)findViewById(R.id.MAIN_SLIDE_INFO_TEXTVIEW_TERMS_ONE);
		textView[4] =(TextView)findViewById(R.id.MAIN_SLIDE_INFO_TEXTVIEW_TERMS_TWO);
		textView[5] =(TextView)findViewById(R.id.MAIN_SLIDE_INFO_TEXTVIEW_TERMS_THREE);
		textView[6] =(TextView)findViewById(R.id.MAIN_SLIDE_INFO_TEXTVIEW_TERMS_LICENSE);	//저작권 정보
		textView[7] =(TextView)findViewById(R.id.MAIN_SLIDE_INFO_TEXTVIEW_COPYRIGHT_TITLE);	//저작권 정보 타이틀.
		textView[0].setText("Where Are You, Kids? 의 줄임말로 내아이가 보다 안전한 환경에서 뛰놀 수 있는 환경조성을 뜻합니다.\n어린이 안심서비스로 어린이집 및 유치원의 우리아이 등.하원 정보와 통학차량의 탑승정보를 부모님에게 전달하고 정보를 전산화 하여 기록, 관리하는 서비스입니다.");
		textView[1].setText("E-mail - WAUKIDS@rmtechs.co.kr\n전화번호 - 070-7004-2807");
		textView[2].setText("* Universal Image Loader(1.9.3)\nApache License 2.0\nhttp://www.apache.org/licenses/LICENSE-2.0\nhttps://github.com/nostra13/Android-Universal-Image-Loader\nfor Image Processing\n\n"
									+"* PagerSlidingTabStrip(1.0.1)\nApache License 2.0\nhttp://www.apache.org/licenses/LICENSE-2.0\nhttps://github.com/astuetz/PagerSlidingTabStrip\nfor used by tab sliding\n\n"
									+"* gesture-imageview\nApache License 2.0\nhttp://www.apache.org/licenses/LICENSE-2.0\nhttps://github.com/jasonpolites/gesture-imageview\nfor used by tab sliding");
		for (int i = 0; i < textView.length; i++) {
			textView[i].setOnClickListener(this);
		}
		
	}
	
	private void setToolbar() {
		toolbar = (Toolbar)findViewById(R.id.MAIN_SLIDE_INFO_TOOLBAR);
		toolbar.setNavigationOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}
	@Override
	public void onClick(View v) {
		Main_JoinYacguan aaaa = new Main_JoinYacguan();
		switch (v.getId()) {
		case R.id.MAIN_SLIDE_INFO_TEXTVIEW_TERMS_ONE:		//이용약관.
			
			startActivity(new Intent(this, Main_Slide_Info_Yacguan.class).putExtra("INFO_FOCUS", "FIRST"));
			break;
		case R.id.MAIN_SLIDE_INFO_TEXTVIEW_TERMS_TWO:		//개인정보 수집 및 이용.
			startActivity(new Intent(this, Main_Slide_Info_Yacguan.class).putExtra("INFO_FOCUS", "SECOND"));
			break;
		case R.id.MAIN_SLIDE_INFO_TEXTVIEW_TERMS_THREE:		//개인정보 취급방침.
			startActivity(new Intent(this, Main_Slide_Info_Yacguan.class).putExtra("INFO_FOCUS", "THIRD"));

			break;
		case R.id.MAIN_SLIDE_INFO_TEXTVIEW_TERMS_LICENSE:		//저작권 정보 클릭 시.
			if (license_clock == 0) {
				textView[2].setVisibility(View.VISIBLE);
				textView[7].setVisibility(View.VISIBLE);
				license_clock=1;
			} else if(license_clock == 1){
				textView[2].setVisibility(View.GONE);
				textView[7].setVisibility(View.GONE);
				license_clock=0;
			}
			break;

		}
	}
	
	private final BroadcastReceiver mToastMessageReceiver = new BroadcastReceiver() {
		public void onReceive(Context context, Intent intent) {
			LinearLayout layout = (LinearLayout)getLayoutInflater().inflate(R.layout.toast_layout, null);
			TextView toast_tv = (TextView)layout.findViewById(R.id.TOAST_LAYOUT_TV);
			Toast toast = new Toast(Main_Slide_Info.this);
			toast.setView(layout);
			toast_tv.setText(intent.getStringExtra("PUSH_NAME")+" : "+intent.getStringExtra("PUSH_SUB"));
			toast.setDuration(Toast.LENGTH_LONG);
			toast.show();
		}
	};
	
}
